<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Story
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
class Story_Widget_ProfileBodyController extends Engine_Content_Widget_Abstract
{
	public function indexAction()
	{
		// Don't render this if not authorized
		$viewer = Engine_Api::_()->user()->getViewer();
		if( !Engine_Api::_()->core()->hasSubject() ) {
			return $this->setNoRender();
		}

		// Get subject and check auth
		$this->view->story = $subject = Engine_Api::_()->core()->getSubject('story');

		if( !($subject instanceof Story_Model_Story) ) {
			return $this->setNoRender();
		}
		
		if($subject->canView(Story_Model_Category::PHOTO_STORY)){
			return $this->setNoRender();
		}				
		
		// if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
		// 	return $this->setNoRender();
		// }

		$request = Zend_Controller_Front::getInstance()->getRequest();
		$chapter_id = $request->getParam('chapter_id');
		
		$chapter = null;
		if(empty($chapter_id)){
			$chapter = null;
		} else {
			$chapter = $subject->getPart($chapter_id);
		}
		$this->view->chapter = $chapter;
		$this->view->chapter_id = $chapter_id;
		$this->view->last_chapter = $subject->getFirstChapter();
		$story = $subject;
		$photo_url = "";
		$photo_id = 0;
		$story_id = 0;		
		if($story){
			$photo = $story->getPhoto();
			if($photo) {
				$photo_url = $photo->getPhotoUrl();
				$photo_id = $story->photo_id;
				$story_id = $story->getIdentity();
				$this->view->photo = $photo;
			}
			
			
		}
		$this->view->photo_url = $photo_url;
		$this->view->photo_id  = $photo_id;
		$this->view->story_id  = $story_id;
	}
}